package com.qifan.alb2b.action.back;


import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qifan.alb2b.domain.CountryInfoDomain;
import com.qifan.alb2b.service.CountryInfoService;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.ID;
import com.qifan.alb2b.util.Page;

/**
 * 国家后台管理ajax的CURD
 * @author hc24
 *
 */
@Controller
@RequestMapping("/admin/country")
public class CountryManageController {
	private CountryInfoService countryInfoService;

	public void setCountryInfoService(CountryInfoService cityInfoService) {
		this.countryInfoService = cityInfoService;
	}
	
	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,CountryInfoDomain cid) {
		//spring太给力了，可以自动装配两个对象  会自动的装返回的Map转换成JSON对象
		return countryInfoService.query(dgm,cid);
	}
	
	@RequestMapping("/getCountry.adm")
	@ResponseBody
	public CountryInfoDomain getCityById(String cid){
		return countryInfoService.getCountryById(cid);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Map<String, Object> add(CountryInfoDomain cityInfoDomain){
		Map<String, Object> map=new HashMap<String, Object>();
		cityInfoDomain.setCountryId(ID.next()+"");//设置唯一ID
		countryInfoService.add(cityInfoDomain);
		map.put("success", true);
		return map;
	}
	
	@RequestMapping("/update.adm")
	@ResponseBody
	public Map<String, Object> update(CountryInfoDomain countryInfoDomain){
		Map<String, Object> map=new HashMap<String, Object>();
		countryInfoService.update(countryInfoDomain);
		map.put("success", true);	
		return map;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Map<String, Object> delete(@RequestParam("cid") String id){
		Map<String, Object> map=new HashMap<String, Object>();
		countryInfoService.delete(id);
		map.put("success", true);
		return map;
	}
}
